xc=8;yc=8;lp2=8;ap2=16;bp2=16 -- lp=32;ap=64;bp=64
lp=255/lp2
ap=255/ap2
bp=255/bp2
function INT(a)
  return(a-a%1)
  end
for y1=0,height-1,yc do
  progress(y1/height)
  for x1=0,width-1,xc do
    as=0
    bs=0
    sd=0
    for y2=0,yc-1,1 do
      for x2=0,xc-1,1 do
        x=x1+x2
        y=y1+y2
        lq,aq,bq=get_lab(x,y)
        lr=(lq*255)/100
        ar=((100+aq)*255)/200
        br=((100+bq)*255)/200
        print (lr)
        print (ar)
        print (br)
        as=as+ar
        bs=bs+br
        sd=sd+1
        end;end
    af=as/sd
    bf=bs/sd
    az=(INT(af/ap))*ap
    bz=(INT(bf/bp))*bp
    for y2=0,yc-1,1 do
      for x2=0,xc-1,1 do
        x=x1+x2
        y=y1+y2
        lq,aq,bq=get_lab(x,y)
        lr=(lq*255)/100
        ar=((100+aq)*255)/200
        br=((100+bq)*255)/200
        lz=(INT(lr/lp))*lp
        set_lab(x,y,(lz*100)/255,((az*200)/255)-100,((bz*200)/255)-100)
        end;end;end;end
flush()

